package org.prism.call;

import java.util.concurrent.Callable;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.FutureTask;

/**
 * 实现Callable接口
 */
public class CallableTest1 {
    public static void main(String[] args) {
        FutureTask<Integer> futureTask = new FutureTask<>(new Person());
        Thread t1 = new Thread(futureTask);
        t1.start();
        try {
            Integer count = futureTask.get();
            System.out.println("count = " + count);
        } catch (ExecutionException | InterruptedException e) {
            e.printStackTrace();
        }
    }
}
class Person implements Callable<Integer>{

    @Override
    public Integer call() throws Exception {
        Integer count = 0;
        for (int i = 0; i <= 100; i++) {
            count += i;
        }
        return count;
    }
}
